﻿using System;
using System.Collections.Generic;
using OperationPlugins.Handlers;

namespace OperationPlugins.Mvc.Filters
{
    /// <summary>
    /// Used to tell that the current action method should invoke plugins handlers, meaning <see cref="IHandler"/> implementations, 
    /// to handle its data.
    /// 
    /// To use this, apply this attribute to a controller class.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    public class UseActionMethodHandlersForAllActionsAttribute : UsePluginHandlersForAllActionsAttribute
    {
        /// <summary>
        /// Initializes a new instance of the UseActionMethodHandlersForAllActionsAttribute class.
        /// </summary>
        /// <param name="moments">The moment when plugin handlers should be invoked.</param>
        public UseActionMethodHandlersForAllActionsAttribute(ActionMethodMoment moments)
            : base(moments)
        {
        }

        protected override IEnumerable<object> GetValuesToHandle()
        {
            yield return new ActionMethodInfo
                {
                    CurrentMoment = base.CurrentMoment,
                    ActionParameters = base.ActionParameters,
                    ActionExecutingContext = base.ActionExecutingContext,
                    ResultExecutingContext = base.ResultExecutingContext,
                    ResultExecutedContext = base.ResultExecutedContext
                };
        }

    }
}
